"""
2017.06.04
"""


def sanitize(time_string):
    """
    过滤(净化)
    :param time_string:
    :return:
    """
    if '-' in time_string:
        splitter = '-'
    elif ':' in time_string:
        splitter = ':'
    else:
        return time_string
    (mins, secs) = time_string.split(splitter)
    return mins + '.' + secs


# 读取教练的数据
def get_coach_data(filename):
    try:
        with open(filename) as f:
            line = f.readline()
        return line.strip().split(',')
    except IOError as err:
        print('File error: ' + str(err))
        return None


# 将sarah数据文件转为一个列表
sarah = get_coach_data('sarah2.txt')
# pop(0) 调用将删除并返回列表前面的数据项。两个pop(0)调用则会删除前两个数据值，并把它们赋给指定的变量。
# (sarah_name, sarah_dob) = sarah.pop(0), sarah.pop(0)
# print(sarah_name + "'s fastest times are: " + str(sorted(set([sanitize(t) for t in sarah]))[0:3]))

# 使用dict
sarah_data = {}
sarah_data['Name'] = sarah.pop(0)
sarah_data['Dob'] = sarah.pop(0)
sarah_data['Times'] = sarah
print(sarah_data['Name'] + "'s fastest times are: "
      + str(sorted(
    set([sanitize(t) for t in sarah_data['Times']]))[0:3]))
